import requests
import pandas as pd
my_key = "b9971b2d4dba9debb61d42df654e6ac0"
#地理编码
def geocode(key,address):
    geocode_url:"https://restapi.amap.com/v3/geocode/geo?parameters" #此url为地理编码url
    params = {
        "key":key,
        "address":address,
    }
    r = requests.get("https://restapi.amap.com/v3/geocode/geo?parameters",params=params)
    results = r.json()['geocodes'][0]['location']
    return results

#逆地理编码
def regeo(key,location,extensions="base",poitype=None,radius=None,roadlevel=None):
    url = "https://restapi.amap.com/v3/geocode/regeo?parameters"
    params = {
        "key":key,
        "location":location,
        "extensions":extensions,
        "poitype":poitype,
        "radius":radius,
        "roadlevel":roadlevel,
    }
    r = requests.get('https://restapi.amap.com/v3/geocode/regeo?parameters',params=params)
    return r.json()


#步行路径规划
def walk(key,origin,destination):
    url_walk = "https://restapi.amap.com/v3/direction/walking?parameters"
    params_walk = {
        "key":key,
        "origin":origin,
        "destination":destination
    }
    r = requests.get(url_walk,params_walk)
    results = r.json()
    return results


#公交路线规划
def bus(key,origin,destination,city):
    url_bus:"https://restapi.amap.com/v3/direction/transit/integrated?parameters"
    params_bus = {
        "key":key,
        "origin":origin,
        "destination":destination,
        "city":city
    }
    r = requests.get("https://restapi.amap.com/v3/direction/transit/integrated?parameters",params_bus)
    results = r.json()
    return results

#驾车路径规划
def drive(key,origin,destination):
    drive_url:"https://restapi.amap.com/v3/direction/driving?parameters"
    params = {
        "key":key,
        "origin":origin,
        "destination":destination
    }
    r = requests.get("https://restapi.amap.com/v3/direction/driving?parameters",params=params)
    results = r.json()
    return results

#骑行路线规划
def bicycle(key,origin,destination):
    bicycle_url:"https://restapi.amap.com/v4/direction/bicycling?parameters"
    params_bicycle = {
        "key":key,
        "origin":origin,
        "destination":destination
    }
    r = requests.get("https://restapi.amap.com/v4/direction/bicycling?parameters",params_bicycle)
    results = r.json()
    return results

#货车路径规划
def truck(key,origin,destination,size):
    truck_url:"https://restapi.amap.com/v4/direction/truck?parameters"
    params_truck = {
        "key":key,
        "origin":origin,
        "destination":destination,
        "size":size
    }
    r = requests.get("https://restapi.amap.com/v4/direction/truck?parameters",params_truck)
    results = r.json()
    return results

#距离测量
def dis(key,origin,destination):
    dis_url:"https://restapi.amap.com/v3/distance?parameters"
    params_dis = {
        "key":key,
        "origin":origin,
        "destination":destination
    }
    r = requests.get("https://restapi.amap.com/v3/distance?parameters",params_dis)
    results = r.json()
    return results

#行政区域查询
def district(key,keywords,subdistricts):
    district_url = "https://restapi.amap.com/v3/config/district?parameters"
    params_district = {
        'key':key,
        'keywords':keywords,#规则：只支持单个关键词语搜索关键词支持：行政区名称、citycode、adcode.
        'subdistricts':subdistricts #规则：设置显示下级行政区级数（行政区级别包括：国家、省/直辖市、市、区/县、乡镇/街道多级数据）可选值：0、1、2、3等数字，并以此类推
    }
    r = requests.get('https://restapi.amap.com/v3/config/district?parameters',params_district)
    results = r.json()
    return results

#关键字搜索
def poi(key,keywords,city,types):
    poi_url:"https://restapi.amap.com/v3/place/text?parameters"
    params_poi = {
        'key':key,
        'city':city,
        'keywords':keywords,#规则： 多个关键字用“|”分割,若不指定city，并且搜索的为泛词（例如“美食”）的情况下，返回的内容为城市列表以及此城市内有多少结果符合要求。
        "types":types#查询POI类型.可选值：分类代码 或 汉字（若用汉字，请严格按照附件之中的汉字填写）
    }
    r = requests.get('https://restapi.amap.com/v3/place/text?parameters',params_poi)
    results = r.json()
    return results

#周边搜索
def around(key,location):
    around_url:'https://restapi.amap.com/v3/place/around?parameters'
    params_around = {
        'key':key,
        'location':location#中心点坐标 规则： 经度和纬度用","分割，经度在前，纬度在后，经纬度小数点后不得超过6位
    }
    r = requests.get('https://restapi.amap.com/v3/place/around?parameters',params_around)
    results = r.json()
    return results

#多边形搜索
def pol(key,polygon,keywords):
    pol_url:"https://restapi.amap.com/v3/place/polygon?parameters"
    params_pol = {
        "key":key,
        "polygon":polygon,#经纬度坐标对，规则：经度和纬度用","分割，经度在前，纬度在后，坐标对用"|"分割。经纬度小数点后不得超过6位。多边形为矩形时，可传入左上右下两顶点坐标对；其他情况下首尾坐标对需相同。
        "keywords":keywords #查询关键字，规则： 多个关键字用“|”分割
    }
    r = requests.get("https://restapi.amap.com/v3/place/polygon?parameters",params_pol)
    results = r.json()
    return results

#ID查询
def ID(key,id):
    ID_url:"https://restapi.amap.com/v3/place/detail?parameters"
    params_ID = {
        "key":key,
        "id":id #兴趣点ID，兴趣点的唯一标识ID
    }
    r = requests.get("https://restapi.amap.com/v3/place/detail?parameters",params_ID)
    results = r.json()
    return results

#IP定位
def ip(key,ip):
    ip_url:"https://restapi.amap.com/v3/ip?parameters"
    params_ip = {
        'key':key,
        'ip':ip #需要搜索的IP地址（仅支持国内）。若用户不填写IP，则取客户http之中的请求来进行定位
    }
    r = requests.get('https://restapi.amap.com/v3/ip?parameters',params_ip)
    results = r.json()
    return results

#静态地图
def map(key,location,zoom):
    map_url:"https://restapi.amap.com/v3/staticmap?parameters"
    params_map = {
        'key':key,
        'location':location, #经纬度
        'zoom':zoom   #缩放级别[1,17]
    }
    r = requests.get('https://restapi.amap.com/v3/staticmap?parameters',params_map)
    results = r.url
    return results

#坐标转换
def convert(key,locations):
    convert_url:"https://restapi.amap.com/v3/assistant/coordinate/convert?parameters"
    params_convert = {
        'key':key,
        'locations':locations, #坐标点，经度和纬度用","分割，经度在前，纬度在后，经纬度小数点后不得超过6位。多个坐标对之间用”|”进行分隔最多支持40对坐标。
    }
    r = requests.get('https://restapi.amap.com/v3/assistant/coordinate/convert?parameters',params_convert)
    results = r.json()
    return results

#天气查询
def weather(key,city):
    weather_url:'https://restapi.amap.com/v3/weather/weatherInfo?parameters'
    params_weather = {
        'key':key,
        'city':city,
    }
    r = requests.get('https://restapi.amap.com/v3/weather/weatherInfo?parameters',params_weather)
    results = r.json()
    return results

#输入提示
def shuru(key,keywords,city):
    shuru_url:"https://restapi.amap.com/v3/assistant/inputtips?parameters"
    params_shuru = {
        "key":key,
        "keywords":keywords, #查询关键词
        "city":city #可选值：citycode、adcode，不支持县级市。填入此参数后，会尽量优先返回此城市数据，但是不一定仅局限此城市结果
    }
    r = requests.get("https://restapi.amap.com/v3/assistant/inputtips?parameters",params_shuru)
    results = r.json()
    return results

#交通态势
def jiaotong(key,rectangle):
    jiaotong_url:"https://restapi.amap.com/v3/traffic/status/rectangle?parameters"
    params_jiaotong = {
        "key":key,
        "rectangle":rectangle #代表此为矩形区域查询。左下右上顶点坐标对。矩形对角线不能超过10公里,两个坐标对之间用”;”间隔,xy之间用”,”间隔
    }
    r = requests.get("https://restapi.amap.com/v3/traffic/status/rectangle?parameters",params_jiaotong)
    results = r.json()
    return results
